<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0,maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
  <title>Document</title>
  <style>

  </style>
</head>

<body>
  <div style="width: 600px; height: 400px;"></div>

  <button>更换数据</button>
  <script src="./lib/echarts.min.js"></script>

</body>
<script>
  let myChart = echarts.init(document.querySelector('div'))

  let option = {
    xAxis: {
      type: 'category',
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line',
        smooth: true
      }
    ]
  }
  myChart.setOption(option)


  document.querySelector('button').addEventListener('click', function () {
    // 更换图表数据，非常简单
    // 首先把配置项中的数据修改
    option.xAxis.data = ['1', '2', '3', '4', '5', '6']
    option.series[0].data = [100, 200, 130, 150, 120, 210]
    option.series[0].type = 'bar'
    // 然后重新创建图表即可
    myChart.setOption(option)
  })
</script>

</html>